<?php
$sql = "
CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_problem` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `weid` INT(10) DEFAULT '0',
  `title` varchar(50) DEFAULT '' COMMENT '问题',
  `answer` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '正确答案值',
  `status` tinyint(1) DEFAULT '0' COMMENT '状态 0正常 1禁用',
  `level` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '难度级别 0简单 1中等 2困难',
  PRIMARY KEY (`id`),
  KEY `idx_uniacid` (`weid`),
  KEY `idx_status` (`status`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
		
CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_footer` (
	`id` int(11) NOT NULL AUTO_INCREMENT,
	`weid` int(11) DEFAULT '0',
	`title` varchar(50) DEFAULT '',
	`color` varchar(10) DEFAULT '' COMMENT '默认颜色',
	`thumb` varchar(255) DEFAULT '',
	`url` varchar(255) DEFAULT '',
	`displayorder` int(10) DEFAULT '0',
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_friends` (
	`weid` int(11) DEFAULT '0',
	`mid` int(11) DEFAULT '0' COMMENT '会员id',
	`shareid` int(11) DEFAULT '0' COMMENT '分享人id',
	`type` tinyint(1) DEFAULT '0' COMMENT '游戏 0：1~500 1：1~49 2：答题',
	`num` int(10) DEFAULT '0',
	 UNIQUE KEY `mid_shareid_type` (`shareid`,`mid`,`type`),
	 KEY `idx_uniacid` (`weid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;	

CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_form` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `mid` int(11) default 0,
   `formid` varchar(50),
   `createtime` int(10) default 0,
   PRIMARY KEY (`id`),
   KEY `mid` (`mid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;		

CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_phrase` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `phrase` varchar(50),
   PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
	
CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_pic` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `weid` INT(10) DEFAULT '0',
  `thumb` varchar(255) DEFAULT '' COMMENT '图片',
  `answers` varchar(255) DEFAULT '' COMMENT '备选答案',
  `answer` varchar(100) DEFAULT '' COMMENT '正确答案',
  `status` tinyint(1) DEFAULT '0' COMMENT '状态 0正常 1禁用',
  PRIMARY KEY (`id`),
  KEY `idx_uniacid` (`weid`),
  KEY `idx_status` (`status`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;		

CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_games` (
	`id` int(11) NOT NULL AUTO_INCREMENT,
	`weid` int(11) DEFAULT '0',
	`title` varchar(100) DEFAULT '',
	`thumb` varchar(255) DEFAULT '',
	`des` varchar(150) DEFAULT '',
	`dummy_num` int(11) DEFAULT '0',
	`num` int(11) DEFAULT '0',
	`url` varchar(255) DEFAULT '',
	`appid` varchar(50) DEFAULT '',
    `status` tinyint(1) DEFAULT '0' COMMENT '状态 0正常 1禁用',
	`sort` int(10) DEFAULT '0',
	PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;		

CREATE TABLE IF NOT EXISTS `ims_junsion_challeng_music` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `music` varchar(255) DEFAULT '' COMMENT '歌曲',
  `answer` varchar(100) DEFAULT '' COMMENT '正确答案',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
		
";

pdo_run($sql);

if (!pdo_fieldexists('junsion_challeng_reward', 'remark')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_reward') . " ADD  `remark` varchar(250) DEFAULT '' COMMENT '备注';");
}
if (!pdo_fieldexists('junsion_challeng_mem', 'reward_num')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_mem') . " ADD  `reward_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '中奖次数';");
}
if (!pdo_fieldexists('junsion_challeng_mem', 'reward_price')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_mem') . " ADD  `reward_price` int(11) NOT NULL DEFAULT '0.00' COMMENT '中奖价值';");
}
if (!pdo_fieldexists('junsion_challeng_mem', 'outtimetoken')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_mem') . " ADD  `outtimetoken` text COMMENT '超时token';");
}
if (!pdo_fieldexists('junsion_challeng_mem', 'shareids')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_mem') . " ADD  `shareids` text COMMENT '邀请人id';");
}
if (!pdo_fieldexists('junsion_challeng_reward', 'type')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_reward') . " ADD  `type` tinyint(1) DEFAULT '0' COMMENT '游戏 0：1~500 1：1~49 2：答题';");
}
if (!pdo_fieldexists('junsion_challeng_gift', 'isdefault')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_gift') . " ADD  `isdefault` tinyint(1) DEFAULT '0' COMMENT '默认 0是 1否';");
}
if (!pdo_fieldexists('junsion_challeng_problem', 'title')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_problem') . " ADD  `title` varchar(255) DEFAULT '' COMMENT '问题';");
}
if (!pdo_fieldexists('junsion_challeng_mem', 'gametoken')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_mem') . " ADD  `gametoken` varchar(50) DEFAULT '' COMMENT '';");
}
if (!pdo_indexexists('junsion_challeng_mem', 'propenid')) {
	pdo_query("ALTER TABLE " . tablename('junsion_challeng_mem') . " ADD  UNIQUE `propenid` (`propenid`) ;");
}
